package dcutils.cards.mtg;

/**
* Represents a colorless mana type in Magic the Gathering.<br/>
* @author dca
*/
public class ColorlessMana implements Mana {
	/** The name of the mana.<br/> */
	private String name = "colorless";

	/** The number of colorless mana.<br/> */
	private Integer num;

	/**
	 * The constructor initializes the num to null,
	 * indicating X colorless mana.<br/>
	 */
	public ColorlessMana() {
		this.num = null; // null implies X
	} // END constructor

	/**
	 * The constructor initializes the number of colorless mana.<br/>
	 * @param num
	 */
	public ColorlessMana(Integer num) {
		this.num = num;
	} // END constructor

	/**
	 * The getter for the name of the colorless mana.<br/>
	 * This is always "colorless".<br/>
	 * @return String "colorless"<br/>
	 */
	public String getName() {
		return this.name;
	} // END getName

	/**
	 * The getter for the number of colorless mana.<br/>
	 * @return Integer The number of colorless mana.<br/>
	 */
	public Integer getNum() {
		return this.num;
	} // END getNum

	/**
	 * Returns a string representation of the colorless mana.<br/>
	 * This will be either:<br/>
	 * {@literal #}:colorless<br/>
	 * X:colorless<br/>
	 * @return String The colon delimited number and name of this colorless mana.<br/>
	 */
	@Override
	public String toString() {
		return String.format(
			"%s:%s",
			(null != num ? num : "X"), getName()
		);
	} // END toString

	/**
	 * Decides if an object is equal to this colorless mana.<br/>
	 * In order for an object to be equal to this colorless mana:<br/>
	 * The object must also be colorless mana, and must have the same number.<br/>
	 * @param obj The item to check for value equality.<br/>
	 * @return True or false<br/>
	 */
	@Override
	public boolean equals(Object obj) {
		if(null == obj) {
			return false;
		} else if(obj instanceof ColorlessMana) {
			ColorlessMana mana = (ColorlessMana)obj;
			return mana.getNum() == this.getNum();
		} else {
			return false;
		} // END if/else
	} // END equals

	/**
	 * Creates a hash code for this colorless mana.<br/>
	 * The hash code uses prime numbers and the number of colorless mana.<br/>
	 * @return integer The hash code.<br/>
	 */
	@Override
	public int hashCode() {
		int hashCode = 101;
		if(null != num) hashCode = (11 * hashCode) + num;
		return hashCode;
	} // END hashCode
} // END class ColorlessMana
